package com.kt.io;

import java.io.Closeable;
import java.io.IOException;

import com.kt.
ExceptionsKt;
import com.kt.Metadata
;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001c\n\u0000\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0003\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003\u001a\u0018\u0010\u0000\u001a\u00020\u0001*\u0004\u0018\u00010\u00022\b\u0010\u0003\u001a\u0004\u0018\u00010\u0004H\u0001\u001aK\u0010\u0005\u001a\u0002H\u0006\"\n\b\u0000\u0010\u0007*\u0004\u0018\u00010\u0002\"\u0004\b\u0001\u0010\u0006*\u0002H\u00072\u0012\u0010\b\u001a\u000e\u0012\u0004\u0012\u0002H\u0007\u0012\u0004\u0012\u0002H\u00060\tH\bø\u0001\u0000ø\u0001\u0001\u0002\n\n\b\b\u0001\u0012\u0002\u0010\u0001 \u0001¢\u0006\u0002\u0010\u000b\u0002\u000f\n\u0006\b\u0011(\n0\u0001\n\u0005\b20\u0001¨\u0006\f"}, d2 = {"closeFinally", "", "Ljava/io/Closeable;", "cause", "", "use", "R", "T", "block", "Lkotlin/Function1;", "Requires newer compiler version to be inlined correctly.", "(Ljava/io/Closeable;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;", "kotlin-stdlib"}, k = 2, mv = {1, 4, 0})
/* compiled from: Closeable.kt */
public final class CloseableKt {
    /* JADX WARNING: Code restructure failed: missing block: B:14:0x002a, code lost:
        r4 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:15:0x002b, code lost:
        com.kt.jvm.internal.InlineMarker.finallyStart(1);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:16:0x0033, code lost:
        if (com.kt.internal.PlatformImplementationsKt.apiVersionIsAtLeast(1, 1, 0) == false) goto L_0x0035;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:17:0x0035, code lost:
        if (r5 != null) goto L_0x0039;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:19:?, code lost:
        r5.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:21:0x003f, code lost:
        closeFinally(r5, r4);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x0042, code lost:
        com.kt.jvm.internal.InlineMarker.finallyEnd(1);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:23:0x0046, code lost:
        throw r4;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static final <T extends Closeable, R> R use(T r5, com.kt.jvm.functions.Function1<? super T, ? extends R> r6) {
        /*
            r0 = 0
            r1 = 0
            java.lang.Throwable r1 = (java.lang.Throwable) r1
            r2 = 0
            r3 = 1
            java.lang.Object r4 = r6.invoke(r5)     // Catch:{ all -> 0x0025 }
            com.kt.jvm.internal.InlineMarker.finallyStart(r3)
            boolean r2 = com.kt.internal.PlatformImplementationsKt.apiVersionIsAtLeast(r3, r3, r2)
            if (r2 == 0) goto L_0x001a
            closeFinally(r5, r1)
            goto L_0x0020
        L_0x001a:
            if (r5 != 0) goto L_0x001d
            goto L_0x0020
        L_0x001d:
            r5.close()
        L_0x0020:
            com.kt.jvm.internal.InlineMarker.finallyEnd(r3)
            return r4
        L_0x0025:
            r4 = move-exception
            r1 = r4
            throw r4     // Catch:{ all -> 0x002a }
        L_0x002a:
            r4 = move-exception
            com.kt.jvm.internal.InlineMarker.finallyStart(r3)
            boolean r2 = com.kt.internal.PlatformImplementationsKt.apiVersionIsAtLeast(r3, r3, r2)
            if (r2 != 0) goto L_0x003f
            if (r5 == 0) goto L_0x0042
            r5.close()     // Catch:{ all -> 0x003d }
            goto L_0x0042
        L_0x003d:
            r2 = move-exception
            goto L_0x0042
        L_0x003f:
            closeFinally(r5, r1)
        L_0x0042:
            com.kt.jvm.internal.InlineMarker.finallyEnd(r3)
            throw r4
        */
        throw new UnsupportedOperationException("Method not decompiled: com.kt.io.CloseableKt.use(java.io.Closeable, com.kt.jvm.functions.Function1):java.lang.Object");
    }

    public static final void closeFinally(Closeable $this$closeFinally, Throwable cause) {
        if ($this$closeFinally != null) {
            if (cause == null) {
                try {
                    $this$closeFinally.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return;
            }
            try {
                $this$closeFinally.close();
            } catch (Throwable closeException) {
                ExceptionsKt.addSuppressed(cause, closeException);
            }
        }
    }
}
